namespace egret.socketio {
    export enum _emReadyState {
        OPENING,
        OPEN,
        CLOSING,
        CLOSED,
        PAUSING,
        PAUSED,
    }

    export enum _emEvent {
        EVENT_OPEN = "open",
        EVENT_CLOSE = "close",
        EVENT_PACKET = "packet",
        EVENT_MESSAGE = "message",
        EVENT_ERROR = "error",
        EVENT_UPGRADE_ERROR = "upgradeError",
        EVENT_FLUSH = "flush",
        EVENT_DRAIN = "drain",
        EVENT_HANDSHAKE = "handshake",
        EVENT_UPGRADING = "upgrading",
        EVENT_UPGRADE = "upgrade",
        EVENT_PACKET_CREATE = "packetCreate",
        EVENT_HEARTBEAT = "heartbeat",
        EVENT_DATA = "data",
        EVENT_CONNECT = "connect",
        EVENT_CONNECTING = "connecting",
        EVENT_CONNECT_ERROR = "connect_error",
        EVENT_CONNECT_TIMEOUT = "connect_timeout",
        EVENT_DISCONNECT = "disconnect",
        EVENT_RECONNECT = "reconnect",
        EVENT_RECONNECT_ERROR = "reconnect_error",
        EVENT_RECONNECT_FAILED = "reconnect_failed",
        EVENT_RECONNECT_ATTEMPT = "reconnect_attempt",
        EVENT_RECONNECTING = "reconnecting",
        EVENT_PING = "ping",
        EVENT_PONG = "pong",
        EVENT_TRANSPORT = "transport",
        EVENT_REQUEST_HEADERS = "requestHeaders",
        EVENT_RESPONSE_HEADERS = "responseHeaders",
        EVENT_POLL = "poll",
        EVENT_POLL_COMPLETE = "pollComplete",
        EVENT_DECODED = "decoded"
    }

    export interface Packet {
        type: number;
        id?: number;
        data?: any;
        nsp?: string;
        query?: string;
        attachments?: number;
        options?: any;
    }

    export function toArray(list: Array<any>, index?: number): Array<any> {
        let array = [];

        index = index || 0;

        for (let i = index || 0; i < list.length; i++) {
            array[i - index] = list[i];
        }

        return array;
    }

    export function isArray(arr) {
        return {}.toString.call(arr) == '[object Array]';
    }
}

interface Error {
    data?: any;
    code?: any;
    transport?: any;
}
